package com.zhoulei.employee;
import java.util.*;
import java.time.*;

/**
 * Employee 雇员类
 */
public class Employee extends Person {
    //私有静态成员 用于标识下一个id
    private static int nextId = 0;
    //私有字段
    //private String name = "";
    private int id;
    private LocalDate date;
    private double salary;

    //静态数据块 用于静态变量初始化  主要是静态变量的初始比较复杂时采用
    static
    {
        //生成随机数
        Random ran = new Random();
        nextId = ran.nextInt(1000);
    }

    //实例域 初始化代码块 用于初始化字段 一般不采用这种做法 还是在构造函数中采用
    {
        //this.name = "";
        this.id = 0;
        this.date = LocalDate.now();
        this.salary = 0.0;
    }

    //构造--注意特有的this方法调用其他的构造函数
    public Employee()
    {
//        this.name = "";
//        this.id = 0;
//        this.date = LocalDate.now();
        //this 调用其他构造
        this("",nextId ++,LocalDate.now(),0.0);
    }
    public Employee(String name, int id, LocalDate date,double salary)
    {
        super(name);
        //this.name = name;
        this.id = id;
        this.date = date;
        this.salary = salary;
        nextId ++;
    }
    public Employee(String name, int id)
    {
        this(name,id,LocalDate.now(),0.0);
        nextId ++;
    }

    //属性
/*    public String getName() {
        return name;
    }*/

    public int getId(){
        return this.id;
    }

    public double getSalary() {
        return this.salary;
    }

    //功能方法
    public double raiseSalary(double percent){
        this.salary *= 1 + percent / 100;
        return this.salary;
    }

    //--实现抽象方法
    public String getDes() {
        return String.format("an employee with a salary of $%.2f", this.getSalary());
    }

}

